function matchDivHeights() {
    var main = $("#main div.main");
    var nav = $("#left_nav");
    
    if($.browser.msie && $.browser.version == 6) {
        if(nav.attr("offsetHeight") < main.attr("offsetHeight")) {
            nav.css("height", main.attr("offsetHeight") + "px");
        }
        else {
            main.css("height", nav.attr("offsetHeight" + "px"));
        }
    }
    else {
        if(nav.css("height")< main.css("height")) {
            nav.css("height", main.css("height"));
        }
        else {
            main.css("height", nav.css("height"));
        }
    }
}

function toggleTables(element)
{
    var table;
    element.parentNode.className = "current";
    switch(element.id)
    {
        case "limo_link":
            document.getElementById("suv_link").parentNode.className = "";
            document.getElementById("policy_link").parentNode.className = "";
            document.getElementById("limo_table").style.display = "block";
            //document.getElementById("sedan_table").style.display = "none";
            document.getElementById("suv_table").style.display = "none";
            document.getElementById("policies").style.display = "none";
            break;
        case "suv_link":
            document.getElementById("limo_link").parentNode.className = "";
            document.getElementById("policy_link").parentNode.className = "";
            document.getElementById("suv_table").style.display = "block";
            document.getElementById("limo_table").style.display = "none";
            document.getElementById("policies").style.display = "none";
            break;
        case "policy_link":
            document.getElementById("limo_link").parentNode.className = "";
            document.getElementById("suv_link").parentNode.className = "";
            document.getElementById("suv_table").style.display = "none";
            document.getElementById("limo_table").style.display = "none";
            document.getElementById("policies").style.display = "block";
            break;
        default:
            //do nothing
    }
}

function showReservationField(check) {
    var section = $('#pick_up');
    if(check.checked) {
        $(section).fadeIn(500);
    }
    else {
        $(section).fadeOut(500);
    }
    matchDivHeights();
}

function prepareTabs() {
    if(!document.getElementsByTagName) { return false; }
    if(!document.getElementById) { return false; }
    if(!document.getElementById("tabs")) { return false; }

    var tab_links = $("#tabs a");
    
    tab_links.each(function (tab_link) {
        $(tab_link).click(function(link) {
            toggleTables(link);
            matchDivHeights();
            return false;
        });
    });
}

function prepareCheckBox() {
    if($("#round_trip").length < 1) { return false; }
    if($('#pick_up').length < 1) { return false; }
    
    $('#round_trip').click(function () { showReservationField(this); });
    if(!$('#round_trip').attr("checked")) { $('#pick_up').fadeOut(500); }
}

function detectResolution() {
    dimObj = $('body').getDimensions();

    /*if(dimObj.width <= 1024)
    {
        $('small').disabled = false;
        if($('ie_small')) $('ie_small').disabled = false;

        $('logo').src = 'images/amtranslogo-7-small.gif';
        var links = $('main_nav').getElementsByTagName('a');

        for(var i = 0; i < links.length; i++)
        {
            links[i].className = '';
            links[i].className= 'nav_image_small';
        }
    }
    else
    {
       $('small').disabled = true;
        if($('ie_small')) $('ie_small').disabled = true;
    }
    <%= stylesheet_link_tag 'alternate_small', { :id => 'small'} %>
    <%= stylesheet_link_tag 'ie_alternate_small', { :id => 'ie_small'} %>
    */
    matchDivHeights();
}

function fixPNG() {
     if ($.browser.msie && $.browser.version == 6) {
        $("#header").supersleight();
        $("#home").supersleight();
    }
}

function animateFleet() {
    $('#sedan').fadeIn(1000);
    $('#suv').fadeIn(2000);
    $('#limo').fadeIn(3000);
    $('#van').fadeIn(4000);
}

function setMinHeightForFleetPage() {
    if(($.browser.msie && $.browser.version == 6) && ($("#fleet").length > 0)) {
        $("#fleet").css("height", "518px");
    }
}

function setUpDatepickers() {
    $("#reservation_reserve_for_string, #reservation_pick_up_at_string").datepicker({
        showOn: 'button',
        buttonImage: '/images/calendar_date_select/calendar.gif',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true
    });
}
$(document).ready(function() {
    if($.browser.opera) {
        $("#main").css("opacity", 0.8);
    }
    setMinHeightForFleetPage();
    prepareTabs();
    prepareCheckBox();
    animateFleet();
    setUpDatepickers();
    matchDivHeights();
    fixPNG();
});